home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / pibt3sp3.arc / RECEIVEM.PAS < prev    next >
Pascal/Delphi Source File  |  1985-10-05  |  10KB  |  263 lines

  1. (*----------------------------------------------------------------------*)
  2. (*       Receive_Modem7_File --- Download file with Modem7/Telink       *)
  3. (*----------------------------------------------------------------------*)
  4.  
  5. PROCEDURE Receive_Modem7_File( Use_CRC: BOOLEAN );
  6.  
  7. (*----------------------------------------------------------------------*)
  8. (*                                                                      *)
  9. (*     Procedure:  Receive_Modem7_File                                  *)
  10. (*                                                                      *)
  11. (*     Purpose:    Downloads file to PC using Modem7/Telink batch       *)
  12. (*                                                                      *)
  13. (*     Calling Sequence:                                                *)
  14. (*                                                                      *)
  15. (*        Receive_Modem7_File( Use_CRC : BOOLEAN);                      *)
  16. (*                                                                      *)
  17. (*           Use_CRC --- TRUE to use CRC checking;                      *)
  18. (*                       FALSE to use checksum checking.                *)
  19. (*                                                                      *)
  20. (*     Calls:   KeyPressed                                              *)
  21. (*              Async_Send                                              *)
  22. (*              Async_Receive                                           *)
  23. (*              Receive_Xmodem_File                                     *)
  24. (*                                                                      *)
  25. (*      Remarks:                                                        *)
  26. (*                                                                      *)
  27. (*         This routine performs the "echo file name" function of       *)
  28. (*         Modem7, required by batch Modem7 and Telink.                 *)
  29. (*                                                                      *)
  30. (*----------------------------------------------------------------------*)
  31.  
  32. CONST
  33.    MaxTry     = 5;
  34.    MaxNoise   = 10;
  35.  
  36. VAR
  37.    RFileName   : AnyStr;
  38.    Int_Ch      : INTEGER;
  39.    Int_Ch_Save : INTEGER;
  40.    Ch          : CHAR;
  41.    CheckSum    : INTEGER;
  42.    EndFName    : BOOLEAN;
  43.    I           : INTEGER;
  44.    Local_Save  : Saved_Screen_Ptr;
  45.    Tname       : STRING[10];
  46.    Tries       : INTEGER;
  47.    NTries      : INTEGER;
  48.    Batch_Title : AnyStr;
  49.  
  50. (*----------------------------------------------------------------------*)
  51. (*              Check_KeyBoard --- Check for keyboard input             *)
  52. (*----------------------------------------------------------------------*)
  53.  
  54. PROCEDURE Check_KeyBoard;
  55.  
  56. BEGIN (* Check_KeyBoard *)
  57.                                    (* If Alt_R found, stop transfer *)
  58.    IF KeyPressed THEN
  59.       BEGIN
  60.  
  61.          READ( Kbd, Ch );
  62.  
  63.          IF ( Ch = CHR( ESC ) ) AND KeyPressed THEN
  64.             BEGIN
  65.                READ( Kbd, Ch );
  66.                IF ORD( Ch ) = Alt_R THEN
  67.                   BEGIN
  68.                      Stop_Receive := TRUE;
  69.                      WRITELN('  Alt_R accepted, transfer cancelled.');
  70.                   END;
  71.             END;
  72.  
  73.       END;
  74.  
  75. END   (* Check_KeyBoard *);
  76.  
  77. (*----------------------------------------------------------------------*)
  78.  
  79. BEGIN (* Receive_Modem7_File *)
  80.                                    (* Open display window for transfers  *)
  81.    Save_Screen( Local_Save );
  82.  
  83.    CASE Transfer_Protocol OF
  84.       Telink     : Tname := 'Telink';
  85.       Modem7_Chk : Tname := 'Modem7 (Checksum)';
  86.       Modem7_CRC : Tname := 'Modem7 (CRC)';
  87.    END (* CASE *);
  88.                                    (* Telink is always CRC mode *)
  89.  
  90.    Use_CRC     := Use_CRC OR ( Transfer_Protocol = Telink );
  91.  
  92.    Batch_Title := 'Batch file download using ' + Tname;
  93.  
  94.    Draw_Menu_Frame( 2, 2, 79, 24, Menu_Frame_Color,
  95.                     Menu_Text_Color, Batch_Title );
  96.  
  97.    Writelne( Batch_Title , FALSE );
  98.  
  99.    Window( 3, 3, 78, 23 );
  100.                                    (* Flag if keyboard halt or EOT *)
  101.                                    (* encountered                  *)
  102.    Stop_Receive := FALSE;
  103.                                    (* Purge reception to remove noise  *)
  104.    Async_Purge_Buffer;
  105.                                    (* Loop over file names         *)
  106.    REPEAT
  107.                                    (* Initialize checksum          *)
  108.       CheckSum := 0;
  109.                                    (* Initialize file name         *)
  110.       RFileName := '';
  111.                                    (* Try up to MaxTry times to    *)
  112.                                    (* send NAK to say we're ready  *)
  113.                                    (* for the file name.           *)
  114.       REPEAT
  115.                                    (* Send NAK                         *)
  116.          Async_Send( CHR( NAK ) );
  117.                                    (* Get response -- should be ACK    *)
  118.                                    (* NOTE:  skip up to MaxNoise chars *)
  119.                                    (*        that are clearly garbage  *)
  120.                                    (*        in effort to get ACK      *)
  121.          NTries := 0;
  122.  
  123.          REPEAT
  124.             Async_Receive_With_TimeOut( Two_Seconds , Int_Ch );
  125.             NTries := NTries + 1;
  126.             Check_Keyboard;
  127.          UNTIL ( Ntries > MaxNoise ) OR
  128.                ( Int_Ch <= 127     ) OR
  129.                Stop_Receive;
  130.  
  131.          Tries := Tries + 1;
  132.  
  133.       UNTIL( Int_Ch = ACK ) OR
  134.            ( Int_Ch = EOT ) OR
  135.            ( Int_Ch = CAN ) OR
  136.            ( Tries  > MaxTry ) OR
  137.            Stop_Receive;
  138.  
  139.                                    (* Only continue if ACK found      *)
  140.  
  141.       Stop_Receive := ( Int_Ch <> ACK ) OR Stop_Receive;
  142.       Int_Ch_Save  := Int_Ch;
  143.  
  144.                                    (* Pick up characters of file name *)
  145.       IF ( NOT Stop_Receive ) THEN
  146.          REPEAT
  147.  
  148.             Async_Receive_With_TimeOut( Five_Seconds , Int_Ch );
  149.  
  150.             Check_KeyBoard;
  151.  
  152.             EndFName := ( Int_Ch = CAN     ) OR
  153.                         ( Int_Ch = EOT     ) OR
  154.                         ( Int_Ch = TimeOut ) OR
  155.                         ( Int_Ch = SUB     ) OR
  156.                         Stop_Receive;
  157.  
  158.             IF ( NOT EndFname ) THEN
  159.                BEGIN
  160.                   Async_Send( CHR( ACK ) );       (* echo 1 char at a time *)
  161.                   RFileName := RFileName + CHR( Int_Ch );
  162.                   Checksum  := ( Checksum + Int_Ch ) AND 255;
  163.                END;
  164.  
  165.          UNTIL EndFname
  166.       ELSE
  167.          Int_Ch  := TimeOut;
  168.  
  169.                                    (* Finished getting filename. *)
  170.       IF ( Int_Ch = SUB ) THEN
  171.          BEGIN  (* Filename received *)
  172.  
  173.                                    (* Send checksum *)
  174.  
  175.             CheckSum := ( CheckSum + Int_Ch ) AND 255;
  176.             Async_Send( CHR( CheckSum ) );
  177.  
  178.                                    (* Get response to checksum *)
  179.  
  180.             Async_Receive_With_TimeOut( Five_Seconds , Int_Ch );
  181.  
  182.             Check_KeyBoard;
  183.                                    (* If checksum OK, do transfer *)
  184.  
  185.             IF ( Int_Ch = ACK ) AND ( NOT Stop_Receive ) THEN
  186.                BEGIN
  187.  
  188.                   FOR  I := LENGTH( RFileName ) TO 11 DO
  189.                      RFileName := RFileName + ' ';
  190.  
  191.                   FileName := Trim( COPY( RFileName, 1, 8 ) );
  192.  
  193.                   IF COPY( RfileName, 9, 3 ) <> '   ' THEN
  194.                      FileName := FileName + '.' + COPY( RFileName, 9, 3 );
  195.  
  196.                                    (* Prevent overwrite of host mode *)
  197.                                    (* files.                         *)
  198.  
  199.                   IF Host_Mode THEN
  200.                      Stop_Receive := Stop_Receive OR
  201.                                      Scan_Xfer_List( FileName )   OR
  202.                                      ( FileName = 'PIBTERM.USF' ) OR
  203.                                      ( FileName = 'PIBTERM.XFR' ) OR
  204.                                      ( FileName = 'PIBTERM.MSG' ) OR
  205.                                      ( FileName = 'PIBTERM.CMT' ) OR
  206.                                      ( FileName = 'PIBTERM.CMT' );
  207.  
  208.                                     (* Get the file. *)
  209.  
  210.                   IF ( NOT Stop_Receive ) THEN
  211.                      BEGIN
  212.  
  213.                         Writelne('  Downloading: ' + FileName , TRUE );
  214.  
  215.                         Receive_Xmodem_File( Use_CRC );
  216.  
  217.                         TextColor( Menu_Text_Color );
  218.  
  219.                      END;
  220.  
  221.                END
  222.             ELSE
  223.                Stop_Receive := TRUE;
  224.  
  225.          END  (* Filename received *)
  226.       ELSE
  227.          Stop_Receive := TRUE;
  228.  
  229.    UNTIL Stop_Receive;
  230.  
  231.                                    (* Acknowledge EOT if received *)
  232.    IF ( Int_Ch_Save = EOT ) THEN
  233.       BEGIN
  234.  
  235.          Async_Send( CHR( ACK ) );
  236.  
  237.          Writelne(' ', TRUE);
  238.          Writelne('  Received EOT from host.' , TRUE );
  239.  
  240.       END
  241.    ELSE
  242.       BEGIN
  243.  
  244.          Writelne( ' ' , TRUE );
  245.          Writelne( '  Transfer cancelled.' , TRUE );
  246.  
  247.       END;
  248.                                    (* Indicate end of transfer    *)
  249.    Writelne(' ', TRUE);
  250.    RvsVideoOn ( Menu_Text_Color, BackGround_Color );
  251.  
  252.    Writelne('  Batch transfer complete.', TRUE);
  253.  
  254.    RvsVideoOff( Menu_Text_Color, BackGround_Color );
  255.  
  256.    DELAY( Two_Second_Delay );
  257.                                    (* Remove batch transfer window *)
  258.    Restore_Screen( Local_Save );
  259.  
  260.    Reset_Global_Colors;
  261.  
  262. END   (* Receive_Modem7_File *);
  263.